<template>
  <view class="chat-container">
    <view class="top-bar">
      <navigator class="back-btn" url="/pages/regularUser/goto/infomation/infomation">←</navigator>
      <text class="title">张三</text>
    </view>

    <scroll-view scroll-y="true" class="message-list" :scroll-top="scrollTop">
      <view class="message-item received">
        <view class="bubble-container">
          <view class="bubble">
            <text>你好！😊</text>
          </view>
          <text class="time">11:30 AM</text>
        </view>
      </view>

      <view class="message-item received">
        <view class="bubble-container">
          <view class="bubble">
            <text>请帮陪我的母亲下楼梯！</text>
          </view>
          <text class="time">11:30 AM</text>
        </view>
      </view>

      <view class="message-item sent">
        <view class="bubble-container">
          <view class="bubble">
            <text>已完成帮助任务请核查！</text>
          </view>
          <text class="time">11:32 AM</text>
        </view>
      </view>
    </scroll-view>

    <view class="input-area">
      <input type="text" placeholder="说些什么吧！" v-model="message" class="input-box" />
      <image src="/static/images/regularUser/send.png" class="send-btn" @click="sendMessage"></image>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      message: '',
      scrollTop: 0
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    sendMessage() {
      if (!this.message.trim()) return;
     
      uni.showToast({ title: '消息已发送', icon: 'success' });
      this.message = '';
      
      this.scrollTop = 10000;
    }
  }
}
</script>

<style>
page {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  height: 100%;
}

.chat-container {
  width: 100%;
  height: 100vh;
  background-color: #FFF7E6;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.top-bar {
  padding: 15px 20px;
  background-color: #fff;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  box-sizing: border-box;
  position: relative;
  flex-shrink: 0;
}

.back-btn {
  font-size: 20px;
  color: black;
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: rgba(255,255,255,0.2);
}

.title {
  font-size: 18px;
  color: black;
  text-align: center;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background-color: #FFF7E6;
  box-sizing: border-box;
  font-size: 15px;
}

.message-item {
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  width: 100%;
  box-sizing: border-box;
}

.message-item.received {
  justify-content: flex-start;
}

.message-item.sent {
  justify-content: flex-end;
}

.bubble-container {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  margin: 0 10px;
  box-sizing: border-box;
}

.message-item.received .bubble-container {
  align-items: flex-start;
  margin-left: 5px;
}

.message-item.sent .bubble-container {
  align-items: flex-end;
  margin-right: 5px;
}

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  word-wrap: break-word;
  box-sizing: border-box;
  position: relative;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.message-item.received .bubble {
  background-color: #fff;
  color: #333;
  border: 1px solid #e0e0e0;
  border-top-left-radius: 5px;
}

.message-item.sent .bubble {
  background: linear-gradient(135deg, #f57f17 0%, #ffa726 100%);
  color: white;
  border-top-right-radius: 5px;
}

.time {
  font-size: 11px;
  color: #999;
  margin-top: 5px;
  padding: 0 5px;
}

.input-area {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  background-color: #fff;
  border-top: 1px solid #eee;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
}

.input-box {
  flex: 1;
  padding: 10px 15px;
  border: 1px solid #ddd;
  border-radius: 25px;
  background-color: #fff;
  font-size: 16px;
  color: #333;
}

.send-btn {
  width: 36px;
  height: 36px;
  margin-left: 10px;
  background-color: #f57f17;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}
</style>